<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<link rel="stylesheet" th:href="@{/assets/css/colorbox.css}"/>
<link rel="stylesheet" th:href="@{/assets/css/fixedColumns.dataTables.css}"/>
<link rel="stylesheet" th:href="@{/assets/css/jquery.dataTables.min.css}"/>
<head th:include="fragments/head::header"/>
<style type="text/css">
    .error {
        color: #F00
    }

    .DTFC_LeftBodyLiner {
        height: 910px ! important;
    }
</style>
<body>
<div th:include="fragments/top::top"></div>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <div th:include="fragments/left::left" class="sidebar" id="sidebar"></div>
        <div class="main-content">
            <!--<div class="breadcrumbs" id="breadcrumbs">-->
            <!--<ul class="breadcrumb">-->
            <!--<li><i class="icon-home home-icon"></i>首页</li>-->
            <!--<li>系统管理</li>-->
            <!--<li>定校方案管理</li>-->
            <!--</ul>-->
            <!--</div>-->

            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="row">
                            <div class="col-xs-12">
                                <h3 class="header smaller lighter blue">定校方案列表</h3>
                                <input type="hidden" name="studentNo" id="studentNo"
                                       th:value="${#httpServletRequest.getParameter('studentNo')}"/>
                                <input type="hidden" id="currentUser" th:value="${session.user.oaid}"/>
                                <input type="hidden" id="planCollegeInfoUrl" th:value="${planCollegeInfoUrl}"/>
                                <input type="hidden" id="planCollegeAuditUrl" th:value="${planCollegeAuditUrl}"/>
                                <shiro:hasPermission name="审核定校方案_规划组">
                                    <input type="hidden" id="isPlanning" th:value="1"/>
                                </shiro:hasPermission>
                                <shiro:hasRole name="运营人员">
                                    <input type="hidden" id="isOperator" th:value="1"/>
                                </shiro:hasRole>
                                <div class="table-responsive">
                                    <div id="alert" class="alert alert-success" style="display: none;" role="alert">
                                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                            <span aria-hidden="true">&times;</span>
                                        </button>
                                        <span id="alertText"></span>
                                    </div>
                                    <table id="sample-table-2" class="table table-striped table-bordered table-hover"
                                           style="white-space: nowrap;">
                                        <thead>
                                        <tr>
                                            <th class="hide">id</th>
                                            <th>学号</th>
                                            <th>学生姓名</th>
                                            <th>分支机构</th>
                                            <th>咨询顾问</th>
                                            <th>定校编号</th>
                                            <th>申请类别</th>
                                            <th>院校名称</th>
                                            <th>课程名称</th>
                                            <th>开课时间</th>
                                            <th>申请截止时间</th>
                                            <th>申请截止时间备注</th>
                                            <th>录入人</th>
                                            <th>录入时间</th>
                                            <th>状态</th>
                                            <th>外联顾问</th>
                                            <th>审批信息</th>
                                            <th>定校信息</th>
                                            <th style="width:75px">操作</th>
                                        </tr>
                                        </thead>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>

        <div th:include="fragments/bottom::bottom"></div>
    </div>

    <a href="#" id="btn-scroll-up"
       class="btn-scroll-up btn btn-sm btn-inverse"> <i
            class="icon-double-angle-up icon-only bigger-110"></i>
    </a>
</div>
<!-- /.main-container -->

<!-- Modal备注 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content"></div>
    </div>
</div>
<div th:include="fragments/js::js"></div>

<script th:src="@{/assets/js/jquery.validate.min.js}"></script>
<script th:src="@{/assets/js/jquery.validate.zh-CN.js}"></script>
<!-- page specific plugin scripts -->
<script charset="UTF-8" th:src="@{/assets/js/1.10.15/jquery.dataTables.min.js}"></script>
<script charset="UTF-8" th:src="@{/assets/js/jquery.dataTables.bootstrap.js}"></script>
<script charset="UTF-8" th:src="@{/assets/js/dataTables.fixedColumns.js}"></script>
<script th:src="@{/assets/js/temp.js}" charset="UTF-8"></script>
<script th:src="@{/business/followService/followService.js}" charset="UTF-8"></script>
<!--图片查看器-->
<script th:src="@{/assets/js/jquery.colorbox-min.js}"></script>
<script th:src="@{/layer/layer.js}"></script>
<script type="text/javascript">

    /*<![CDATA[*/
    var currentUser = $("#currentUser").val();
    var oTable1;
    jQuery(function ($) {
        oTable1 = $('#sample-table-2').dataTable({
            "aLengthMenu": [10,20],  //用户可自选每页展示数量 5条或10条
            // "sScrollY": "450px",
            "scrollX": true,
            "scrollCollapse": true,
            "bProcessing": true,//显示搜索样式
            "bDeferRender": true,//延迟加载表格
            "fixedColumns": { //固定列的配置项
                "leftColumns": 3, //固定左边第一列
            },
            "bFilter": false,//是否使用搜索
            "bProcessing": true,
            "sPaginationType": "bs_normal",//分页样式
            "bRetrieve": true,//是否调用后台
            "bServerSide": true,//是否以后台分页
            "bAutoWidth": true,
            "sAjaxSource": "/planCollege/list/worktable",//请求路径
            "fnServerData": function (sSource, aoData, fnCallback) {
                aoData.push(
                    {"name": "auditStatus", "value":1}
                )
                $.ajax({
                    "dataType": 'json',
                    "type": "POST",
                    "url": sSource,
                    "data": aoData,
                    "success": fnCallback
                });
            },
            "aaSorting": [[0, "desc"]],
            "bSort": true,
            "aoColumns": [

                {"sClass": "center", "bVisible": false, "mData": "id"},//此列不显示

                {
                    "sClass": "center", "bSortable": false, "mData":
                    function (data) {
                        if (data.studentNo != null) {
                            return '<a class="blue" href="javascript:void(0);" onclick="toStudentDetail(\'' + data.studentNo + '\')">' + data.studentNo + '</a>';
                        } else {
                            return "";
                        }
                    }
                },
                {"sClass": "center", "bSortable": false, "mData": "studentName"},
                {"sClass": "center", "bSortable": false, "mData": "branchName"},
                {"sClass": "center", "bSortable": false, "mData": "salesConsultant"},
                {"sClass": "center", "bSortable": false, "mData": "planId"},
                {
                    "sClass": "center", "bSortable": false, "mData":
                    function (data) {
                        if (data.applyType == 0) {
                            return "直录"
                        }
                        if (data.applyType == 1) {
                            return "双录"
                        }
                        if (data.applyType == 2) {
                            return "纯语言"
                        }
                        return "";
                    }
                },
                {"sClass": "center", "bSortable": false, "mData": "collegeName"},
                {"sClass": "center", "bSortable": false, "mData": "courseName"},
                {"sClass": "center", "bSortable": false, "mData": "courseStartTime"},
                {"sClass": "center", "bSortable": false, "mData": "applyDeadline"},
                {"sClass": "center", "bSortable": false, "mData": "applyDeadlineRemark"},
                {"sClass": "center", "bSortable": false, "mData": "operatorName"},
                {"sClass": "center", "bSortable": false, "mData": "createTime"},
                {
                    "sClass": "center", "bSortable": false, "mData": function (data){

                    if(data.auditStatus == 0){
                        return "经理未审核";
                    }
                    else if(data.auditStatus == 2){
                        return "经理已驳回";
                    }
                    else if(data.auditStatus == 3){
                        return "文签已接受";
                    }

                    else if(data.auditStatus == 4){
                        return "已驳回";
                    }
                    else if(data.auditStatus == 5){
                        return "学生已接受";
                    }
                    else if(data.auditStatus == -1){
                        return "学生已驳回";
                    }
                    else if(data.auditStatus == 6){
                        if(data.studentConfirmStatus == 1){
                            if ($("#isPlanning").val() == "1") {
                                return "规划已审核";
                            }
                            else return "学生未确认";
                        }
                        if(data.studentConfirmStatus == 2) {
                            return "学生已确认";
                        }
                    }
                    else if(data.auditStatus == 1){
                        if(data.studentConfirmStatus == 1){
                            return "学生未确认";
                        }
                        else if(data.studentConfirmStatus == 2){
                            if(data.nationId == 4 && data.usaStatus == 1){
                                return "规划未审核";
                            }
                            else {
                                return "学生已确认";
                            }

                        }
                        else if(data.studentConfirmStatus == 0){
                            if(data.nationId == 4 && data.usaStatus == 1){
                                return "规划待审核";
                            }
                            else{
                                return "暂无法确认";
                            }
                        }
                        else{
                            return "";
                        }

                    }
                    else{
                        return "";
                    }

                }
                },
                {"sClass": "center", "bSortable": false, "mData": "connectorName"},
                {
                    "sClass": "center", "bSortable": false, "mData": function (data) {
                    var check = '<a href="javascript:void(0);" onclick="toApproveURL(' + data.id + ')" >点击查看</a>';
                    return check;
                }
                },
                {
                    "sClass": "center", "bSortable": false, "mData": function (data) {
                    var check = '<a href="javascript:void(0);" onclick="toPlanCollegeURL('+data.id+')">点击查看</a>';
                    return check;
                }
                },
                {
                    "sClass": "center", "bSortable": false, "mData": function (data) {
                    var agree = '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="updateStatus(' + data.id + ', 3, ' + data.planId + ')" >接受</a>&nbsp;&nbsp;';
                    var refuse = '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="updateStatus(' + data.id + ', 4, ' + data.planId + ')" >驳回</a>&nbsp;&nbsp;';
                    var audit = '';
                    var operatorStudentConfirm = "";
                    if ($("#isPlanning").val() == "1") {
                        audit = '<a class="blue" href="javascript:void(0);" onclick="audit(\'' + data.id + '\',\'' + data.studentNo + '\')" >规划审核</a>';

                    }
                    if ($("#isOperator").val() == "1") {
                        operatorStudentConfirm = '<a class="blue" href="javascript:void(0);" onclick="operatorStudentConfirm(\'' + data.id + '\',\'' + data.studentNo + '\')" >运营确认</a>';

                    }
                    if(data.auditStatus == 0){
                        return "";
                    }
                    else if(data.auditStatus == 2){
                        return "";
                    }
                    else if(data.auditStatus == 3){
                        return "";
                    }

                    else if(data.auditStatus == 4){
                        return "";
                    }
                    else if(data.auditStatus == 5){
                        return "";
                    }
                    else if(data.auditStatus == -1){
                        return "";
                    }
                    else if(data.auditStatus == 6){
                        if(data.studentConfirmStatus == 2) {
                            if ($("#isPlanning").val() != "1") {
                                return agree + refuse;
                            }
                            else return "";
                        }
                        else if(data.studentConfirmStatus == 1) {
                            return operatorStudentConfirm;
                        }
                        else return "";
                    }
                    else if(data.auditStatus == 1){
                        if(data.studentConfirmStatus == 1){
                            return operatorStudentConfirm;
                        }
                        else if(data.studentConfirmStatus == 2){
                            if(data.nationId == 4 && data.usaStatus == 1){
                                return "";
                            }
                            else {
                                return agree + refuse;
                            }

                        }
                        else if(data.studentConfirmStatus == 0){
                            if(data.nationId == 4 && data.usaStatus == 1){
                                if ($("#isPlanning").val() == "1") {
                                    return audit + refuse;
                                }
                                else return "";
                            }
                            else {
                                return "";
                            }
                        }
                        else{
                            return "";
                        }

                    }
                    else{
                        return "";
                    }

                }
                }
            ],
            "oLanguage": {
                "sLengthMenu": "每页 _MENU_条 ",
                "sZeroRecords": "对不起，查询不到任何相关数据",
                "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录 ",
                "sInfoEmpty": "显示 0 到 0 条，共 0 条记录",
                "sInfoFiltered": "数据表中共为 _MAX_ 条记录)",
                "sProcessing": "正在加载中...",
                "sSearch": "搜索",
                "sUrl": "", //多语言配置文件，可将oLanguage的设置放在一个txt文件中，例：Javascript/datatable/dtCH.txt
                "oPaginate": {
                    "sFirst": "第一页",
                    "sPrevious": " 上一页 ",
                    "sNext": " 下一页 ",
                    "sLast": " 最后一页 "
                }
            }
            //多语言配置

        });

        $("#query").click(function () {
            oTable1.fnDraw();
        })

    })

    //跳转到添加页面
    function toAddUrl() {
        location.href = "";
    }

    //跳转编辑页
    function toEditURL() {
        location.href = "";
    }

    //定校信息
    /*function toPlanCollegeURL(studentNo, planId, id) {
        var planCollegeInfoUrl = $("#planCollegeInfoUrl").val();
        window.open(planCollegeInfoUrl + '?code=edit&collegeId='+id+'&memberid='+currentUser+'&sid='+studentNo);
    }*/
    function toPlanCollegeURL( id) {
        window.open('/selectStudentPlanCollegeDetails?planCollegeId=' + id);
    }

    //定校审批信息
    function toApproveURL(id) {
        window.open('/planCollege/AuditResultList?planCollegeId=' + id);
    }

    //跳转学生详情页
    function toStudentDetail(studentNo) {
        window.open('/student/detail?studentNo=' + studentNo);
    }

    //修改状态
    function updateStatus(id, status, planId) {
        if (status == 3) { //接受
            layer.confirm('确认接受当前定校方案？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                //加载框
                var loadIndex = layer.load(1, {shade: [0.5, '#393D49']});
                $.ajax({
                    url: "/planCollege/updateStatus",
                    type: "post",
                    data: {
                        id: id,
                        status: status,
                    },
                    success: function (data) {
                        layer.close(loadIndex);
                        if (data) {
                            location.reload(true);
                        } else {
                            layer.msg('操作失败', {time: 1000});
                        }
                    }
                });
            }, function () {
                layer.close();
            });
        } else if (status == 4) { //驳回
            layer.open({
                title: "请填写驳回备注",
                type: 2,
                area: ['500px', '280px'],
                fixed: false, //不固定
                btn: ['确定'],
                yes: function (index) {
                    //获得选择的原因
                    var body = layer.getChildFrame('body', index);
                    var reason = body.contents().find("#reason").val();
                    var value = body.contents().find("#reason").find("option:selected").text();
                    var remark = body.contents().find("#remark").val();
                    if(remark.length > 100){
                        layer.msg('备注过长', {time: 1000});
                        return false;
                    }
                    //加载框
                    var loadIndex = layer.load(1, {shade: [0.5, '#393D49']});
                    $.ajax({
                        url: "/planCollege/updateStatus",
                        type: "post",
                        data: {
                            id: id,
                            status: status,
                            reason: remark,
                            planId: planId,
                        },
                        success: function (data) {
                            layer.close(loadIndex);
                            layer.close(index);
                            if (data) {
                                location.reload(true);
                            } else {
                                layer.msg('操作失败', {time: 1000});
                            }
                        }
                    });
                },
                content: '/planCollege/reasonList',
            });
        }
    }

    function assign(id) {
        layer.open({
            title: '选择外联顾问',
            type: 2,
            area: ['500px', '350px'],
            fixed: false, //不固定
            btn: ['确定'],
            yes: function (index) {
                //获得选中的顾问
                var body = layer.getChildFrame('body', index);
                var oaid = body.contents().find("#connector").val();
                var name = body.contents().find("#connector").find("option:selected").text();
                if (oaid != "") {
                    //加载框
                    var loadIndex = layer.load(1, {shade: [0.5, '#393D49']});
                    $.ajax({
                        url: "/planCollege/assign",
                        type: "post",
                        data: {
                            id: id,
                            status: status,
                            oaid: oaid,
                            connector: name
                        },
                        success: function (data) {
                            layer.close(loadIndex);
                            layer.close(index);
                            if (data) {
                                location.reload(true);
                            } else {
                                layer.msg('操作失败', {time: 1000});
                            }
                        },
                        error: function (data) {
                            layer.close(loadIndex);
                        }
                    })
                } else {
                    layer.alert('请选择外联顾问！', {
                        icon: 0
                    });
                }
            },
            content: '/planCollege/connector'
        });
    }

    /*]]>*/

</script>
</body>
</html>
